/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.ensma.ia.miniblog.persistence;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PostPersist;
import javax.persistence.PrePersist;
import javax.persistence.PreRemove;
import javax.persistence.PreUpdate;

/**
 *
 * @author LeBlero
 */
@Entity
public class Categorie implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Column(name="nom",nullable=false)
    private String nom;

    public Categorie() {
        this.nom = "";
    }

    public Categorie(String n) {
        this.nom = n;
    }

    public Long getId() {
        return id;
    }

    public String getNom() {
        return nom;
    }

    public void setNom(String nom) {
        this.nom = nom;
    }

    @PrePersist
    private void valdeAvantPersistance() {
        if (id != null || nom != null) {
            System.out.println("Categorie::PrePersist::Erreur avant persistance");
        }
    }

    @PostPersist
    private void valideApresPersistance() {
        if (id == null) {
           System.out.println("Categorie::PostPersist::Erreur durant persistance");
        }
    }

    @PreUpdate
    @PreRemove
    private void valideAvantUpdateOrRemove() {
        if (id == null) {
            System.out.println("Categorie::PreUpdateRemove:Update ou remove impossible, ID null");
        }
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Categorie)) {
            return false;
        }
        Categorie other = (Categorie) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "fr.ensma.ia.miniblog.Categorie[id=" + id + "]";
    }

}
